﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Configuration;
using OgilvyOne.UKNow.Mobile.Model;
using OgilvyOne.UKNow.Mobile.Utilities;
using OgilvyOne.UKNow.Model;

namespace OgilvyOne.UKNow.Mobile.APIs.News
{
    public class Show : IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string newID = context.Request.Params["news_id"];
                int nid = 0;
                if (int.TryParse(newID, out nid))
                {

                }
                NewsModel model = new NewsBLL(2052).selNew(nid);
                if (model != null)
                {
                    NewsInfo newsInfo = new NewsInfo();
                    newsInfo.Content = model.Content;

                    if (!string.IsNullOrEmpty(model.HtmlFileName))
                        newsInfo.HtmlFileName = ConfigCacheManager.DomainName + "/cn/news/" + model.HtmlFileName;
                    else
                        newsInfo.HtmlFileName = string.Format("{0}/cn/news/{1}.html", ConfigCacheManager.DomainName, model.ID);

                    //if (!string.IsNullOrEmpty(model.ImageName))
                    //    newsInfo.ImageName = ConfigCacheManager.DomainName + ConfigCacheManager.FilePath.GetImageVirtualPath(model.ImageName);
                    newsInfo.Images = ModelConvertUtility.GetNewPhoneImages(model.ID);
                    newsInfo.ID = model.ID;
                    newsInfo.Title = model.Title;
                    newsInfo.InsertedTime = DateTimeFormatter.FormatDateTime(model.InsertedTime);

                    string s = JsonSerializationHelper.ObjectToJson(newsInfo);
                    context.Response.Write(ResultUtility.ReturnResultJson("0", s, "获取新闻详情数据成功"));
                }
                else
                {
                    context.Response.Write(ResultUtility.ReturnResultJson("-102", "", "您想要获取的新闻不存在"));
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-102", "", "获取新闻详情数据失败。Message：" + ex.Message));
            }
        }
    }
}
